﻿using System.Threading.Tasks;
using MongoDB.Driver;
using Sustainalytics.Synchronization.Validation.ValidationRules.Common;

namespace Sustainalytics.Synchronization.Validation.Handlers.Common
{
    public class WhiteListCompaniesLoader
    {
        private readonly IMongoCollection<WhiteList> mongoCollection;
        private readonly WhiteListCompanies whiteListCompanies;

        public WhiteListCompaniesLoader(IMongoCollection<WhiteList> mongoCollection, WhiteListCompanies whiteListCompanies)
        {
            this.mongoCollection = mongoCollection;
            this.whiteListCompanies = whiteListCompanies;
        }

        public async Task LoadAsync()
        {
            var values = await mongoCollection.Find(Builders<WhiteList>.Filter.Empty).ToListAsync().ConfigureAwait(false);

            foreach (var value in values)
            {
                whiteListCompanies.Add(value);
            }
        }
    }
}
